package com.bestv.bsr.core.service;

import com.bestv.bsr.core.constants.AiSourceConstants;
import com.bestv.bsr.core.constants.ServiceCodeEnum;
import com.bestv.bsr.core.exceptions.ServiceException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author taojiacheng
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class RecommendEngineFactory {

    private final List<IRecommendEngine> recommendServices;

    public IRecommendEngine getRecommendEngine(String aiSource) {
        if (StringUtils.isEmpty(aiSource)) {
            aiSource = AiSourceConstants.AI_SOURCE_BESTV;
        }
        for (IRecommendEngine recommendEngine : recommendServices) {
            if (recommendEngine.accept(aiSource)) {
                return recommendEngine;
            }
        }
        throw new ServiceException(ServiceCodeEnum.AI_SOURCE_NOT_AVAILABLE);
    }
}
